package org.theonept.travian.t4a.building;

import java.util.ArrayList;
import java.util.List;

import org.theonept.travian.model.Argile;
import org.theonept.travian.model.Bois;
import org.theonept.travian.model.Cereal;
import org.theonept.travian.model.Fer;
import org.theonept.travian.model.Ressource;
import org.theonept.travian.t4a.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListRessourcesAdapter extends ArrayAdapter<Ressource> {
	private List<Ressource> data = new ArrayList<Ressource>();

	/**
	 * @return the data
	 */
	public List<Ressource> getData() {
		return data;
	}

	/**
	 * @param data
	 *            the data to set
	 */
	public void setData(List<Ressource> data) {
		this.data = data;
	}

	private final Activity context;

	public ListRessourcesAdapter(Activity context) {

		super(context, R.layout.village_list_view);
		this.context = context;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Ressource getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return Long.valueOf(data.get(position).getId());
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Ressource ressource = data.get(position);
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.ressource_list_view, parent, false);
		TextView ressourceType = (TextView) rowView.findViewById(R.id.liste_ressource_type);
		TextView ressourceLevel = (TextView) rowView.findViewById(R.id.liste_ressource_level);
		if (ressource instanceof Fer) {
			ressourceType.setText(R.string.fer);
		} else if (ressource instanceof Argile) {
			ressourceType.setText(R.string.argile);
		} else if (ressource instanceof Bois) {
			ressourceType.setText(R.string.bois);
		} else if (ressource instanceof Cereal) {
			ressourceType.setText(R.string.cereal);
		}
		ressourceLevel.setText("lvl " + ressource.getLevel());

		return rowView;
	}

}
